<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <div id="game"></div>
  <script src="gamecore.js"></script>
  <script>

    // LGM.setGameworld([
    //   [4,0,4,0],
    //   [4,0,0,4],
    //   [0,0,0,0],
    //   [4,0,4,0],
    // ]);

    LGM.genRandomWorld(4);
    function writeDocument(output) {
      var world = document.getElementById('game');
      world.innerHTML = '';
      for (var index in output) {
        var p = document.createElement('p');
        var em_txt = document.createTextNode(output[index]);
        p.appendChild(em_txt);
        world.appendChild(p);
      }
    }
    writeDocument(LGM.getGameworld());

    document.addEventListener('keydown', function (e) {
      // console.log("Key is " + e.keyCode);
      if (e.keyCode >= 37 && e.keyCode <= 40) {
        LGM.go(e.key);
        writeDocument(LGM.getGameworld());
      }
    });
  </script>
</body>

</html>